#include <iostream>
using namespace std;

template<class T>
class Stack
{
public:
	//构造函数
	Stack(int newcapacity = 3)
		:_capacity(newcapacity)
		, _size(0)
	{
		_array = new T[newcapacity];
	}
	
	//拷贝构造 
	Stack(const Stack& s)
	{
		if (_array != nullptr)
		{
			s._array = new T[_capacity];
			memcpy(s._array, _array, _size);
		}
	}
	
	//析构
	~Stack()
	{
		if (_array)
		{
			delete[] _array;
			_size = 0;
			_capacity = 0;
		}
	}
	
	//赋值
	Stack& operator=(const Stack& s)
	{
		
	}
	
	//有效个数
	int Size() {
		return _size;
	}
	
	//栈顶元素
	T Top()
	{
		return _array[_size - 1];
	}
	
	//弹栈
	T Pop() {
		if (_size != 0)
		{
			return _array[--_size];
		}
	}
	
	//压栈
	void Push(T x) {
		if (_capacity != _size)
		{
			_array[_size++] = x;
		}
		else
		{
			_array = CheckCapacity();
			_array[_size++] = x;
		}
	}
	
	//为空
	bool Empty() {
		return _size == 0;
	}
	
private:
	//扩容
	T* CheckCapacity()
	{
		if(_size == _capacity)
		{
			T* _newarray = new T[2*_capacity];
			memcpy(_newarray,_array,_capacity);
			delete []_array;
			_array = _newarray;
			_newarray = nullptr;
			return _array;
		}
		return nullptr;
	}
	
private:
	T* _array;
	int _capacity;
	int _size;
};
